package com.abigdreamer.swing.app.skin;

import com.abigdreamer.swing.app.SwingUtil;
import com.abigdreamer.swing.component.JCButton;
import com.abigdreamer.swing.component.UIUtil;
import craky.component.JImagePane;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.border.EmptyBorder;

public class DeleteConfirmPane
  extends JImagePane
{
  private static final long serialVersionUID = 8218959983027142762L;
  private static final Image BG_IMAGE = SwingUtil.getImage("skin_list_bg.png");
  private AlphaComposite COMPOSITE = AlphaComposite.SrcOver.derive(0.75F);
  private SkinMgr skinMgr;
  private JLabel lbInfo;
  private JCButton btnOk;
  private JCButton btnCancel;
  private Skin skin;
  
  public DeleteConfirmPane(SkinMgr skinMgr)
  {
    this.skinMgr = skinMgr;
    this.lbInfo = new JLabel("您确定要删除这个皮肤吗？");
    this.btnOk = new JCButton();
    this.btnCancel = new JCButton();
    initUI();
  }
  
  private void initUI()
  {
    setImageOnly(true);
    setLayout(null);
    setBorder(new EmptyBorder(0, 0, 0, 0));
    this.lbInfo.setBounds(22, 17, 200, 15);
    this.lbInfo.setOpaque(false);
    this.lbInfo.setForeground(new Color(253, 253, 253));
    this.lbInfo.setBorder(new EmptyBorder(0, 0, 0, 0));
    this.lbInfo.setFont(new Font("宋体", 0, 12));
    this.lbInfo.setHorizontalAlignment(2);
    this.lbInfo.setVerticalAlignment(1);
    this.btnOk.setBounds(81, 61, 65, 21);
    this.btnOk.setFocusable(false);
    this.btnOk.putClientProperty("EventKey", "DelSkinOK");
    this.btnOk.setImage(SwingUtil.getImage("skin_del_ok.png", true));
    this.btnOk.setRolloverImage(SwingUtil.getImage("skin_del_ok_rollover.png", true));
    this.btnOk.setPressedImage(this.btnOk.getRolloverImage());
    this.btnOk.addActionListener(this.skinMgr);
    
    this.btnCancel.setBounds(158, 61, 65, 21);
    this.btnCancel.setFocusable(false);
    this.btnCancel.putClientProperty("EventKey", "DelSkinCancel");
    this.btnCancel.setImage(SwingUtil.getImage("skin_del_cancel.png", true));
    this.btnCancel.setRolloverImage(SwingUtil.getImage("skin_del_cancel_rollover.png", true));
    this.btnCancel.setPressedImage(this.btnCancel.getRolloverImage());
    this.btnCancel.addActionListener(this.skinMgr);
    add(this.lbInfo);
    add(this.btnOk);
    add(this.btnCancel);
  }
  
  public void updateBackground(Skin skin, JComponent sameAs)
  {
    this.skin = skin;
    BufferedImage image = UIUtil.getGraphicsConfiguration(this).createCompatibleImage(sameAs.getWidth(), 
      sameAs.getHeight(), 3);
    Graphics2D imageG = image.createGraphics();
    sameAs.paint(imageG);
    imageG.setComposite(this.COMPOSITE);
    imageG.drawImage(BG_IMAGE, 2, 2, null);
    imageG.dispose();
    setImage(image);
  }
  
  public Skin getSkin()
  {
    return this.skin;
  }
}
